//
//  ZRJiaHao.swift
//  XJ8XWB
//
//  Created by 中二 on 2016/10/23.
//  Copyright © 2016年 中二. All rights reserved.
//

import UIKit

class ZRJiaHao: UITabBar {


    var DJiaHao:(()->())?
    
    override init(frame: CGRect) {
       super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func buttonClick(){
        //        hmDelegate?.composeButtonClickOfTabBar()
        // 03- 执行闭包
        DJiaHao?()
    }
    
  private func setupUI(){
        
        addSubview(composeButton)
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        //UITabBarButton 宽度
        let w = ZRPingMuW * 0.2
        var index: CGFloat = 0
        // 遍历subviews
        for value in subviews{
            // 判断是否是我们想要的UITabBarButton
            //UITableViewCell.self  == [UITableViewCell class]
            // 判断 class 一致
            if value.isKind(of: NSClassFromString("UITabBarButton")!) {
                // 设置 x 和 w
                value.frame.size.width = w
                value.frame.origin.x = index * w
                //                index = index + 1   == index += 1
                index += 1
                // 为了给撰写按钮留个位置
                if index == 2 {
                    index += 1
                }
            }
        }
        // 设置撰写按钮的 frame
        composeButton.center.x = ZRPingMuW * 0.5
        composeButton.center.y = frame.size.height * 0.5
    }
    lazy var composeButton: UIButton = {
        let button = UIButton(setImgName: "tabbar_compose_icon_add", backgroundImgName: "tabbar_compose_button", target: self, action: #selector(buttonClick))
        
        return button
        
    }()
    
    
}
